<%@ page import="java.io.InputStream" %>
<%@ page import="java.util.Base64" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
  // 使用pageContext获取servletContext
  ServletContext context = pageContext.getServletContext();
  // 读取resources中的图片
  InputStream inputStream = context.getResourceAsStream("/WEB-INF/classes/img/1.jpg");
  String imageBase64 = "";
  if (inputStream != null) {
    byte[] bytes = inputStream.readAllBytes();
    imageBase64 = Base64.getEncoder().encodeToString(bytes);
  }
%>
<img src="data:image/jpeg;base64, <%= imageBase64 %>" alt="图片">
</body>
</html>
